--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_par_region AS (SELECT * FROM &erp.par_region WHERE 1=2);




DELETE FROM se_par_region;


 INSERT INTO se_par_region
 (SELECT id region_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle region_lib,
         NULL region_lib2
    FROM UV_CREGIONS) ;

 UPDATE se_par_region tf SET enreg_id=(select enreg_id FROM &erp.par_region f WHERE f.region_cod=tf.region_cod) ;
 UPDATE se_par_region tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('region_cod','PAR_REGION','O') ;

 commit;
 
 
select * from (
SELECT &outils.stragg(source) source,region_cod, enreg_id, enreg_s, region_lib, region_lib2
FROM (
  SELECT 'uv' source ,g.* FROM se_par_region g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_region g
  )
GROUP BY region_cod, enreg_id, enreg_s, region_lib, region_lib2
HAVING Count(1)!=2) r
ORDER BY region_cod;